package org.example.lc;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;

class p128 {
    /**
     * max len
     * sub : [0] = 0
     * [1] = 1
     */
    class Solution {

        public int longestConsecutive(int[] nums) {
            Arrays.sort(nums);
            int max=0;
            int cur = -1;
            for(int i=0;i<nums.length;i+=1) {
                if(cur==-1) {
                    cur=1;
                    continue;
                }
                if(nums[i]==nums[i-1]+1) {
                    cur+=1;
                    max = Math.max(max,cur);
                }

                else if(nums[i]>nums[i-1]+1){
                    max = Math.max(max,cur);
                    cur=1;
                }
            }
            max = Math.max(max,cur);
            return max;
        }
    }
    @Test
    public void d1() {
//        assertEquals(4, new Solution().longestConsecutive(new int[]{100,4,200,1,3,2}));
//        assertEquals(9, new Solution().longestConsecutive(new int[]{0,3,7,2,5,8,4,6,0,1}));
        assertEquals(1, new Solution().longestConsecutive(new int[]{0}));

    }
}
